package com.example.jh352160.surfingtv.search;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.example.jh352160.surfingtv.R;
import com.example.jh352160.surfingtv.search.customView.HistoryList;
import com.example.jh352160.surfingtv.search.customView.SearchEditview;
import com.example.jh352160.surfingtv.search.customView.adapter.TagAdapter;
import com.hhl.library.FlowTagLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jh352160 on 2016/7/28
 */

public class SearchPage extends AppCompatActivity {

    Toolbar toolbar;
    ListView historyList;
    HistoryList list;
    SearchEditview editview;
    FlowTagLayout flowTagLayout;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.search_page);

        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("");
        list = (HistoryList) findViewById(R.id.history_list_layout);

        historyList = (ListView) findViewById(R.id.history_list);
        editview = (SearchEditview) findViewById(R.id.search_edit_layout);
        historyList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                TextView text = (TextView) view.findViewById(R.id.text);
                EditText searchEdit = (EditText) findViewById(R.id.search_edit);
                searchEdit.setText(text.getText().toString());
            }
        });
        LinearLayout cleanAll = (LinearLayout) findViewById(R.id.clean_all);
        cleanAll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                list.cleanAllHistory();
                editview.cleanAll();
                list.setVisibility(View.INVISIBLE);
            }
        });
        Button search = (Button) editview.findViewById(R.id.search_button);
        search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                editview.search();
                list.flushList();
            }
        });

        List<String> datas = new ArrayList<>();
        datas.add("12");
        datas.add("12356");
        datas.add("4879789");
        datas.add("4879789");
        datas.add("124879789");
        datas.add("179789");
        datas.add("12379789");
        datas.add("14879789");
        datas.add("1879789");
        datas.add("124879789");
        datas.add("1289");
        flowTagLayout = (FlowTagLayout) findViewById(R.id.flowTagLayout);
        TagAdapter adapter = new TagAdapter(this);
        flowTagLayout.setAdapter(adapter);
        adapter.onlyAddAll(datas);
    }
}
